<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <ul>
          <li v-for="item of page" :key="item.id">
            <img :src="item.imgUrl" alt="">
            <span>{{item.desc}}</span>
          </li>
        </ul>
      </swiper-slide>
    </swiper>
  </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {

      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
@import "~css/mixin.styl"
  .icons
    overflow hidden
    height 0
    padding-bottom 50%
    background #fff
    ul
      display flex
      align-items center
      flex-wrap wrap
      li
        flex 0 0 25%
        height 1.7rem
        overflow hidden
        img
          display block
          width .95rem
          height .95rem
          margin .2rem auto 0
          object-fit cover
        span
          display block
          width 100%
          height .45rem
          line-height .45rem
          font-size .25rem
          text-align center
          ellipsis()
</style>
